<template>
  <div>
    <el-container class="page">
      <el-aside width="200px">
        <el-menu
          class="el-menu-vertical-demo"
          text-color="#fff"
          active-text-color="#ffd04b"
          unique-opened
          router
        >
          <el-menu-item index="/index">
            <i class="el-icon-menu"></i>
            <span slot="title">首页</span>
          </el-menu-item>
          <!-- <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-setting"></i>
            <span>系统设置</span>
            </template>
            <el-menu-item index="/index/menu">菜单管理</el-menu-item>
            <el-menu-item index="/index/role">角色管理</el-menu-item>
            <el-menu-item index="/index/manage">管理员管理</el-menu-item>
          </el-submenu>

          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-goods"></i>
              <span>商城管理</span>
            </template>
            <el-menu-item index="/index/cate">商品分类</el-menu-item>
            <el-menu-item index="/index/specs">商品规格</el-menu-item>
            <el-menu-item index="/index/goods">商品管理</el-menu-item>
            <el-menu-item index="/index/vip">会员管理</el-menu-item>
            <el-menu-item index="/index/banner">轮播图管理</el-menu-item>
            <el-menu-item index="/index/seckill">秒杀活动</el-menu-item>
          </el-submenu>-->

          <div v-for="(item, index) in user.menus" :key="item.id">
            <el-submenu :index="'' + index" v-if="item.children">
              <template slot="title">
                <i :class="item.icon"></i>
                <span>{{ item.title }}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item
                  v-for="i in item.children"
                  :key="i.id"
                  :index="'/index' + i.url"
                >{{ i.title}}</el-menu-item>
              </el-menu-item-group>
            </el-submenu>

            <el-menu-item :index="'/index' + item.url" v-else>
              <i class="el-icon-star-on"></i>
              <span slot="title">{{item.title}}</span>
            </el-menu-item>
          </div>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <div class="right">
            <span>{{user.username}}</span>
            <el-button @click="logout">退出登录</el-button>
          </div>
        </el-header>
        <el-main>
          <el-breadcrumb separator-class="el-icon-arrow-right" class="mianbao">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>
              <a href="/">{{$route.meta.title}}</a>
            </el-breadcrumb-item>
          </el-breadcrumb>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
export default {
  components: {},
  computed: {
    ...mapGetters({
      user: "user",
    }),
  },
  methods: {
    ...mapActions({
      useractions: "useractions",
    }),
    logout() {
      this.useractions({});
      this.$router.push("/login");
    },
  },
  mounted() {
    // console.log(this.user);
  },
  props: [],
  data() {
    return {};
  },
};
</script>
<style lang="less">
@import "../../less/index.less";
.page {
  height: 100vh;
}
.el-aside {
  background: @info;
}
.el-header {
  background: @header-color;
}
.mianbao {
  margin-bottom: @margin;
}
.el-menu-vertical-demo,
.el-menu {
  background: @info;
}
.el-menu-item:focus,
.el-menu-item:hover,
.el-submenu__title:hover {
  background: @header-color;
}
.right {
  position: absolute;
  right: 50px;
  line-height: 60px;
}
.right span {
  font-size: 16px;
}
.right .el-button {
  margin-left: 20px;
}
</style>